package com.wenwei.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wenwei.bean.UserParkBean;
import com.wenwei.parking.R;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by nidalee on 2017/9/30.
 */

public class PopupAdapter extends RecyclerView.Adapter<PopupAdapter.MyViewHolder> {

    private ArrayList<UserParkBean> mList;

    public PopupAdapter(ArrayList<UserParkBean> list ,CallBack callBack) {
        this.mList = list;
        this.mCallBack = callBack;
    }

    public interface CallBack{
        void onItemClick(int position,int parkId);
    }

    private CallBack mCallBack;


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_popup, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.tv.setText(mList.get(position).getParkName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCallBack.onItemClick(position,mList.get(position).getId());
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv)
        TextView tv;
        public MyViewHolder(View v) {
            super(v);
            ButterKnife.bind(this, v);
        }
    }


}
